﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;

namespace YJKElementFinish.WallSurface
{
	public class AddSurfaceFailuresProcessing
	{
		public AddSurfaceFailuresProcessing(string testTransactionName)
		{
			this.m_TestTransactionName = testTransactionName;
		}

		public void OnFailuresProcessing(object sender, FailuresProcessingEventArgs e)
		{
			FailuresAccessor failuresAccessor = e.GetFailuresAccessor();
			string transactionName = failuresAccessor.GetTransactionName();
			IList<FailureMessageAccessor> failureMessages = failuresAccessor.GetFailureMessages();
			if (failureMessages.Count == 0)
			{
				e.SetProcessingResult(0);
				return;
			}
			if (transactionName.Equals(this.m_TestTransactionName))
			{
				foreach (FailureMessageAccessor failureMessageAccessor in failureMessages)
				{
					failuresAccessor.ResolveFailure(failureMessageAccessor);
				}
                e.SetProcessingResult((FailureProcessingResult)1);
				return;
			}
			e.SetProcessingResult(0);
		}

		private string m_TestTransactionName = "";
	}
}
